package com.newzqxq.common.utils;


/**
 * 资料完善程度(位字段):0.绑定身份证实名;1.同盾报告;2.获取运营商信息;3.获取基本信息;4.获取芝麻分;5.获取人脸识别;6.获取联系人信息;7.获取其他信息;8.内部绑卡;9.外部绑卡
 * Created by Administrator on 2017/7/3.
 */
public class BitTools {
    final  static boolean debug=true;
    static final String[] msg={"绑定身份证实名","同盾报告","获取运营商信息","获取基本信息","获取芝麻分","获取人脸识别","获取联系人信息","获取其他信息","内部绑卡","外部绑卡"};
    public static final boolean isTrueBitFlag(final int data,final int bit){
        return (data & (1<<bit)) == (1<<bit);
    }

    public static final int setBitFlagTrue(final int data,final int bit){
        return (data | (1<<bit));
    }

    public static final int setBitFlagFalse(final int data,final int bit){
        return (data & ~(1<<bit));
    }

    public static final int checkBitFlagData(final int data,final int mask){
        return (data & mask)^mask;
    }
    public static String getMsg(int data){
        StringBuffer isb = new StringBuffer(Integer.toBinaryString(data)).reverse();
        StringBuffer sb = new StringBuffer();
         for (int i=0;i<isb.length() && i<msg.length;i++){
             if(isb.charAt(i)=='1'){
                 sb.append(msg[i]).append(",");
             }
         }
        return sb.toString();
    }

    public static void main(String[] args) {
        int ret = checkBitFlagData(0x55,0xEB);
        System.out.println(getMsg(ret));

//         int ret = checkBitFlagData(0x45,0x2B);
//        System.out.println(getMsg(ret));

//        char[] cc = Integer.toBinaryString(ret).toCharArray();
//
//        for (int i=0;i<cc.length;i++){
//            if (cc[i] =='1'){
//                System.out.println(msg[i]);
//            }
//        }
//        System.out.println(checkBitFlagData(0xEB,0x55));
//        System.out.println(checkBitFlagData(7,15));
//        System.out.println(checkBitFlagData(14,7));
//        System.out.println(0xEB);
//        System.out.println(0x55);
////        System.out.println((0xEB&0x55));
//        System.out.println((0x55&0xEB ));
//        System.out.println((0x55&0xEB ^ 0xEB));
//        System.out.println(0xEB^65);
//        System.out.println(  Integer.toBinaryString(170));
        //ok
//        System.out.println(0x7);
//        System.out.println(0xD);
//        System.out.println((0xD&0x7));
//        System.out.println((0x7&0xD));
//        System.out.println((0x7&0xD^0xD));

//        if(debug){
//            System.out.println(  Integer.toBinaryString(data));
//            System.out.println(  Integer.toBinaryString(mask));
//            System.out.println(  Integer.toBinaryString(data & mask));
//            System.out.println(  Integer.toBinaryString(data & mask^mask));
//        }


    }
}
